<template>
  <div class="table-box">
    <div class="requestReportBox ReportBox">
      <h3 class="title">请求报表</h3>
      <el-row :gutter="20" v-auth="'request_report_oneLineSolve'">
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestFRC_line_week', '一线解决率-本周趋势', 'WEEKS', 'true', weekStart, weekEnd)"
          >
            一线解决率-本周趋势
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestFRC', '一线解决率-当天', 'DAYS', 'false', curDate, curDate)"
          >
            一线解决率-当天
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestFRC', '一线解决率-本周', 'WEEKS', 'false', weekStart, weekEnd)"
          >
            一线解决率-本周
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestFRC', '一线解决率-本月', 'MONTHS', 'false', mStart, mEnd)"
          >
            一线解决率-本月
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestFRC', '一线解决率-本年', 'YEARS', 'false', yStart, yEnd)"
          >
            一线解决率-本年
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('requestFRC', '一线解决率', '', 'false')">一线解决率</div>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-auth="'request_report_statisticalState'">
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestStatus_count', '请求状态-本周', 'WEEKS', 'false', weekStart, weekEnd)"
          >
            请求状态-本周
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestStatus_count', '请求状态-本月', 'MONTHS', 'false', mStart, mEnd)"
          >
            请求状态-本月
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestStatus_count', '请求状态-本年', 'YEARS', 'false', yStart, yEnd)"
          >
            请求状态-本年
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('requestStatus_count', '请求状态', '', 'false')">
            请求状态
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestStatus_month', '状态统计', 'YEARS', 'true', yStart, yEnd)"
          >
            状态统计
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-auth="'request_report_assortStatistical'">
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestCatagory', '请求分类-本周', 'WEEKS', 'false', weekStart, weekEnd)"
          >
            请求分类-本周
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestCatagory', '请求分类-本月', 'MONTHS', 'false', mStart, mEnd)"
          >
            请求分类-本月
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestCatagory', '请求分类-本年', 'YEARS', 'false', yStart, yEnd)"
          >
            请求分类-本年
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('requestCatagory', '请求分类', '', 'false')">请求分类</div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestCategory_Count_month', '分类统计', 'YEARS', 'true', yStart, yEnd)"
          >
            分类统计
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-auth="'request_report_slaResponse'">
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_response_line_week', 'SLA响应率-本周趋势', 'WEEKS', 'true', weekStart, weekEnd)"
          >
            SLA响应率-本周趋势
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_response', '响应率-当天', 'DAYS', 'true', curDate, curDate)"
          >
            SLA响应率-当天
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_response', 'SLA响应率-本周', 'WEEKS', 'true', weekStart, weekEnd)"
          >
            SLA响应率-本周
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_response', 'SLA响应率-本月', 'MONTHS', 'true', mStart, mEnd)"
          >
            SLA响应率-本月
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_response', 'SLA响应率-本年', 'YEARS', 'true', yStart, yEnd)"
          >
            SLA响应率-本年
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('requestSLA_response', 'SLA响应率 ', '', 'true')">
            SLA响应率
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-auth="'request_report_slaFulfill'">
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_complete_line_week', 'SLA完成率-本周趋势', 'WEEKS', 'true', weekStart, weekEnd)"
          >
            SLA完成率-本周趋势
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_complete', '完成率-当天', 'DAYS', 'true', curDate, curDate)"
          >
            SLA完成率-当天
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_complete', 'SLA完成率-本周', 'WEEKS', 'true', weekStart, weekEnd)"
          >
            SLA完成率-本周
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_complete', 'SLA完成率-本月', 'MONTHS', 'true', mStart, mEnd)"
          >
            SLA完成率-本月
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('requestSLA_complete', 'SLA完成率-本年', 'YEARS', 'true', yStart, yEnd)"
          >
            SLA完成率-本年
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('requestSLA_complete', 'SLA完成率', '', 'true')">
            SLA完成率
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-auth="'request_report_technicianManHourStatistical'">
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('engineerWorkload', '技术员工作量-当天', 'DAYS', 'false', curDate, curDate)"
          >
            技术员工作量-当天
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('engineerWorkload', '技术员工作量-本周', 'WEEKS', 'false', weekStart, weekEnd)"
          >
            技术员工作量-本周
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('engineerWorkload', '技术员工作量-本月', 'MONTHS', 'false', mStart, mEnd)"
          >
            技术员工作量-本月
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('engineerWorkload', '技术员工作量-本年', 'YEARS', 'false', yStart, yEnd)"
          >
            技术员工作量-本年
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('engineerWorkload', '技术员工作量 ', '', 'false')">
            技术员工作量
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="4" v-auth="'request_report_technicianBusynessStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="getPurestatReportData('workload_Status_Statistics', '技术员忙碌程度统计', 'false')"
          >
            技术员繁忙程度统计
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianDisposeTimeConsuming'">
          <div class="grid-content ep-bg-purple" @click="selectDate('tc_takeTime_perRequest', '技术员处理请求耗时', '', 'true')">
            技术员处理请求耗时
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Technicians_deal_with_statistics', '技术员处理请求统计', '', 'false')"
          >
            技术员处理请求统计
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div class="grid-content ep-bg-purple" @click="selectDate('Technician_Cost_Time', '技术员工时统计报表', '', 'true')">
            技术员工时统计报表
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Consultant_handle_client_requests_Statistics', '月度报表按技术员工作量', '', 'false')"
          >
            月度报表按技术员工作量
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_statisticalState'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Classification_status_request_statistics', '月度报表按状态', '', 'false')"
          >
            月度报表按状态
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_assortStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Separate_statistics_number_customer_requests', '月度报表按分类', '', 'false')"
          >
            月度报表按分类
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('customer_request_number_statistical', '月度报表按客户', '', 'false')"
          >
            月度报表按客户
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Monthly_report_by_state_hours', '月度报表按技术员（工时）', '', 'false')"
          >
            月度报表按技术员（工时）
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Monthly_report_by_state_hours', '月度报表按状态（工时）', '', 'false')"
          >
            月度报表按状态（工时）
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Monthly_report_module_working_hours', '月度报表按分类（工时）', '', 'false')"
          >
            月度报表按分类（工时）
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_technicianManHourStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Monthly_report_by_customer_working_hours', '月度报表按客户（工时）', '', 'false')"
          >
            月度报表按客户（工时）
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-auth="'request_report_technicianManHourStatistical'">
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('According_to_the_packet_response_rate', '按照公司分组响应率', '', 'false')"
          >
            按照公司分组响应率
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('In_accordance_with_the_institutions_packet_response_rate', '按照机构分组响应率', '', 'false')"
          >
            按照机构分组响应率
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_materielCostStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('Request_processing_material_cost_trends', '请求物料成本趋势', 'YEARS', 'false', yStart, yEnd)"
          >
            请求物料成本趋势
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_materielCostStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('The_statistics_requested_materials_costs', '请求物料成本统计', '', 'false')"
          >
            请求物料成本统计
          </div>
        </el-col>
        <el-col :span="4" v-auth="'request_report_materielCostStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="
              getReportView('Grouping_statistics_monthly_cost_materials', '请求物料成本总统计', 'YEARS', 'true', yStart, yEnd)
            "
          >
            请求物料成本总统计
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Customers_and_state_statistics', '客户请求统计', '', 'false')"
          >
            客户请求统计
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20" v-auth="'request_report_technicianManHourStatistical'">
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('Internal_Discussion', '请求月度报表', '', 'false')">
            请求月度报表
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Operation_and_maintenance_workload_monthly_statistical_reports', '按请求分类统计', '', 'false')"
          >
            按请求分类统计
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Monthly_staff_group_workload_statistics', '按技术组和技术员请求数量统计', '', 'false')"
          >
            按技术组和技术员请求数量统计
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('SLA_treatment_completion_rate_report', '技术组及人员SLA完成率', '', 'true')"
          >
            技术组及人员SLA完成率
          </div>
        </el-col>
        <el-col :span="4">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('The_average_processing_time_report', '平均处理时间报表', '', 'true')"
          >
            平均处理时间报表
          </div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content ep-bg-purple" @click="selectDate('Request_detailed_display', '请求详细报表', '', 'true')">
            请求详细报表
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="cimReportBox ReportBox">
      <h3 class="title">资产报表</h3>
      <el-row :gutter="20">
        <el-col :span="4" v-auth="'configItem_report_configItemTotalStatistical'">
          <div class="grid-content ep-bg-purple" @click="getCimReportView('ciCategory', '配置项分类报表', 'false')">
            资产统计报表
          </div>
        </el-col>
        <el-col :span="4" v-auth="'configItem_report_configItemState'">
          <div class="grid-content ep-bg-purple" @click="getCimReportView('ciStatus', '配置项状态报表', 'false')">
            配置项状态报表
          </div>
        </el-col>
        <el-col :span="4" v-auth="'configItem_report_configItemTotalStatistical'">
          <div class="grid-content ep-bg-purple" @click="getCimReportView('CICategoryAndStatus', '配置项总体统计', 'false')">
            配置项总体统计
          </div>
        </el-col>
        <el-col :span="4" v-auth="'configItem_report_configItemAssort'">
          <div
            class="grid-content ep-bg-purple"
            @click="
              getReportView(
                'Classification_of_state_assets_statistics',
                '按分类和状态统计资产原值-本月',
                'MONTHS',
                'false',
                mStart,
                mEnd
              )
            "
          >
            按分类和状态统计资产原值-本月
          </div>
        </el-col>
        <el-col :span="4" v-auth="'configItem_report_configItemAssort'">
          <div
            class="grid-content ep-bg-purple"
            @click="
              getReportView(
                'Classification_of_state_assets_statistics',
                '按分类和状态统计资产原值-本年',
                'YEARS',
                'false',
                yStart,
                yEnd
              )
            "
          >
            按分类和状态统计资产原值-本年
          </div>
        </el-col>
        <el-col :span="4" v-auth="'configItem_report_configItemAssort'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Classification_of_state_assets_statistics', '按分类和状态统计资产原值', '', 'false')"
          >
            按分类和状态统计资产原值
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="4" v-auth="'configItem_report_assetOriginalValueStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="getCimReportView('Assets_at_cost_trend_chart', '资产原值的趋势图', 'false')"
          >
            资产原值的趋势图
          </div>
        </el-col>
        <el-col :span="4" v-auth="'configItem_report_configItemTotalStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Resource_depreciation_rate_statistics', '资源折旧率统计报表', '', 'false')"
          >
            资源折旧率统计报表
          </div>
        </el-col>
        <el-col :span="4" v-auth="'configItem_report_configItemTotalStatistical'">
          <div class="grid-content ep-bg-purple" @click="selectDate('ci_requests_Tables', '配置项故障统计', '', 'false')">
            配置项故障统计
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="visitReportBox ReportBox">
      <h3 class="title">用户回访率统计</h3>
      <el-row :gutter="20">
        <el-col :span="4" v-auth="'userRevisit_report_revisitJake'">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('visit_rate_current', '回访满意率-本周', 'WEEKS', 'false', weekStart, weekEnd)"
          >
            回访满意率-本周
          </div>
        </el-col>
        <el-col :span="4" v-auth="'userRevisit_report_revisitJake'">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('visit_rate_current', '回访满意率-本月', 'MONTHS', 'false', mStart, mEnd)"
          >
            回访满意率-本月
          </div>
        </el-col>
        <el-col :span="4" v-auth="'userRevisit_report_revisitJake'">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('visit_response_currentYear', '回访满意率-本年', 'YEARS', 'true', yStart, yEnd)"
          >
            回访满意率-本年
          </div>
        </el-col>
        <el-col :span="4" v-auth="'userRevisit_report_revisitJake'">
          <div
            class="grid-content ep-bg-purple"
            @click="getReportView('visit_rate_month_x', '回访满意率总体统计-本年', 'YEARS', 'true', yStart, yEnd)"
          >
            访满意率总体统计-本年
          </div>
        </el-col>
        <el-col :span="4" v-auth="'userRevisit_report_userRevisitStatistical'">
          <div
            class="grid-content ep-bg-purple"
            @click="selectDate('Satisfaction_scores_Statistics', '技术员回访率分数统计报表', '', 'false')"
          >
            技术员回访率分数统计报表
          </div>
        </el-col>
        <el-col :span="4" v-auth="'ReturnVisit'">
          <div class="grid-content ep-bg-purple" @click="dialogVisitManage = true">回访记录管理</div>
        </el-col>
      </el-row>
    </div>
    <!-- <div class="setReportBox ReportBox">
      <h3 class="title">自定义报表</h3>
    </div> -->
  </div>
  <el-dialog v-model="dialogVisible" :title="titleText" width="80%">
    <div v-html="ReportData"></div>
  </el-dialog>
  <el-dialog v-model="dialogDate" :title="titleText" width="30%">
    <el-form>
      <el-form-item label="公司/客户" v-if="showAssignee === true">
        <el-input v-model="company" placeholder="请选择公司/客户" @click="selectCompany"></el-input>
      </el-form-item>
      <el-form-item label="技术员" v-if="showAssignee === true">
        <el-input v-model="Assignee" placeholder="请选择技术员" @click="selectAssignee"></el-input>
      </el-form-item>
      <el-form-item label="技术员" v-if="showEngineer === true">
        <el-input v-model="engineer" placeholder="请选择技术员" @click="selectEngineer"></el-input>
      </el-form-item>
      <el-form-item label="开始日期">
        <el-date-picker
          v-model="startDate"
          type="date"
          placeholder="选择日期"
          size="default"
          value-format="YYYY-MM-DD"
          :disabled-date="disabledDate"
        />
      </el-form-item>
      <el-form-item label="结束日期">
        <el-date-picker
          v-model="endDate"
          type="date"
          placeholder="选择日期"
          size="default"
          value-format="YYYY-MM-DD"
          :disabled-date="disabledDate"
        />
      </el-form-item>
      <el-form-item label="操作">
        <el-button type="primary" @click="getReportView(fileName, titleText, showHide, confirm, startDate, endDate)">
          生成报表
        </el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
  <el-dialog title="选择技术员" v-model="dialogRuleRequestNoTableVisible">
    <div :style="{ height: '500px' }">
      <Userselect @send-data="sendRuleRequestNoData" />
    </div>
  </el-dialog>
  <el-dialog title="选择技术员" v-model="dialogAssignee">
    <div :style="{ height: '500px' }">
      <Userselect @send-data="sendAssigneeId" />
    </div>
  </el-dialog>
  <el-dialog title="选择公司/客户" v-model="dialogRuleCompanyNoTableVisible">
    <div :style="{ height: '500px' }">
      <CustemerSelect @send-data="sendRuleCompanyNoData" />
    </div>
  </el-dialog>
  <el-dialog title="回访记录管理" v-model="dialogVisitManage" width="80%">
    <ProTable
      ref="proTable"
      :columns="columns"
      :request-api="getReturnVisitList"
      :init-param="initParam"
      :request-auto="true"
      :data-callback="dataCallback"
      :search-col="{ xs: 1, sm: 1, md: 1, lg: 1, xl: 1 }"
    >
      <!-- 表格操作 -->
      <!-- <template #operation="scope">
        <el-button type="primary" link :icon="View" @click="seeDetails(scope.row)">回访详情</el-button>
        <el-button type="primary" link :icon="EditPen" @click="editEvent(scope.row)">请求详情</el-button>
      </template> -->
    </ProTable>
  </el-dialog>
</template>
<script lang="ts" setup name="reportView">
import { ref, reactive } from "vue";
import { ElMessage } from "element-plus";
import { getReportData, getPurestatReport, getConfigReport, getReturnVisitList } from "@/api/modules/reportView";
import Userselect from "@/views/tools/userselect/index.vue";
import CustemerSelect from "@/views/tools/custemerSelect/index.vue";
import ProTable from "@/components/ProTable/index.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { Delete, EditPen, View, Search } from "@element-plus/icons-vue";
import { useAuthButtons } from "@/hooks/useAuthButtons";
const { BUTTONS } = useAuthButtons();
const disabledDate = (time: Date) => {
  return time.getTime() > Date.now();
};
// 获取本周开始和结束日期的函数
const getCurrentDates = () => {
  const now = new Date();
  const today = now.toISOString().split("T")[0]; // 计算今天的日期
  const firstDayOfWeek = new Date(now.setDate(now.getDate() - now.getDay() + 1)); // 周一
  const lastDayOfWeek = new Date(now.setDate(now.getDate() - now.getDay() + 7)); // 周日
  const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 2); // 本月第一天
  const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 1); // 本月最后一天
  const firstDayOfYear = new Date(now.getFullYear(), 0, 2); // 今年第一天
  const lastDayOfYear = new Date(now.getFullYear(), 11, 32); // 今年最后一天
  return {
    today,
    start: firstDayOfWeek.toISOString().split("T")[0], // 格式化为 YYYY-MM-DD
    end: lastDayOfWeek.toISOString().split("T")[0],
    monthStart: firstDayOfMonth.toISOString().split("T")[0],
    monthEnd: lastDayOfMonth.toISOString().split("T")[0],
    yearStart: firstDayOfYear.toISOString().split("T")[0], // 今年第一天
    yearEnd: lastDayOfYear.toISOString().split("T")[0] // 今年最后一天
  };
};
const {
  today: curDate,
  start: weekStart,
  end: weekEnd,
  monthStart: mStart,
  monthEnd: mEnd,
  yearStart: yStart,
  yearEnd: yEnd
} = getCurrentDates();
const dialogVisible = ref(false);
const dialogDate = ref(false);
const dialogRuleRequestNoTableVisible = ref(false);
const dialogRuleCompanyNoTableVisible = ref(false);
const dialogAssignee = ref(false);
const dialogVisitManage = ref(false);
const showAssignee = ref(false);
const showEngineer = ref(false);
const ReportData = ref("");
const titleText = ref("");
const startDate = ref("");
const endDate = ref("");
const fileName = ref("");
const showHide = ref("");
const confirm = ref("");
const engineer = ref("");
const userId = ref("");
const company = ref("");
const companyNo = ref("");
const Assignee = ref("");
const assigneeId = ref("");
const selectDate = (a, b, c, d) => {
  dialogDate.value = true;
  fileName.value = a;
  titleText.value = b;
  showHide.value = c;
  confirm.value = d;
  showEngineer.value = false;
  showAssignee.value = false;
  if (b === "技术员工时统计报表") {
    showEngineer.value = true;
    showAssignee.value = false;
  }
  if (
    b === "月度报表按技术员工作量" ||
    b === "月度报表按状态" ||
    b === "月度报表按分类" ||
    b === "月度报表按客户" ||
    b === "月度报表按状态（工时）" ||
    b === "月度报表按技术员（工时）" ||
    b === "月度报表按分类（工时）" ||
    b === "月度报表按客户（工时）"
  ) {
    showEngineer.value = false;
    showAssignee.value = true;
  }
  if (b === "请求详细报表") {
    showEngineer.value = true;
    showAssignee.value = true;
  }
};
const getReportView = async (a, b, c, d, e, f) => {
  if (e === "" || e === null || e === "undefined" || f === "" || f === null || f === "undefined") {
    ElMessage.warning("请先选择时间");
    return;
  }
  dialogDate.value = false;
  dialogVisible.value = true;
  titleText.value = b;
  let params;
  if (showEngineer.value && !showAssignee.value) {
    params = {
      "dto.fileName": a,
      "dto.firstDate": e,
      "dto.lastDate": f,
      "dto.userId": userId.value,
      "dto.showHide": c,
      "dto.reporti18n": "zh_CN",
      "dto.confirm": d
    };
  } else if (!showEngineer.value && showAssignee.value) {
    params = {
      "dto.fileName": a,
      "dto.firstDate": e,
      "dto.lastDate": f,
      "dto.companyNo": companyNo.value,
      "dto.assigneeId": assigneeId.value,
      "dto.confirm": d,
      "dto.reporti18n": "zh_CN"
    };
  } else if (showEngineer.value && showAssignee.value) {
    params = {
      "dto.fileName": a,
      "dto.firstDate": e,
      "dto.lastDate": f,
      "dto.userId": userId.value,
      "dto.assigneeId": assigneeId.value,
      "dto.showHide": c,
      "dto.reporti18n": "zh_CN",
      "dto.confirm": d
    };
  } else {
    params = {
      "dto.fileName": a,
      "dto.firstDate": e,
      "dto.lastDate": f,
      "dto.showHide": c,
      "dto.reporti18n": "zh_CN",
      "dto.confirm": d
    };
  }
  const data = await getReportData(params);
  let data_set = data.toString();
  const parser = new DOMParser();
  const doc = parser.parseFromString(data_set, "text/html");
  const reportMain = doc.getElementById("reportMain");
  if (reportMain) {
    const firstDiv = reportMain.querySelector("div");
    if (firstDiv) {
      firstDiv.style.display = "none"; // 替换为你想要的样式
    }
  }
  data_set = doc.body.innerHTML; // 更新 data_set
  if (data_set.indexOf("/itsm-webapp") > -1) {
    data_set = data_set.replaceAll("/itsm-webapp", "/api");
  }
  if (data_set.indexOf("../") > -1) {
    data_set = data_set.replaceAll("../", "/api/");
  }
  if (data_set.indexOf("reports!") > -1) {
    data_set = data_set.replaceAll("reports!", "api/reports!");
  }
  ReportData.value = data_set;
  startDate.value = "";
  endDate.value = "";
  engineer.value = "";
  userId.value = "";
  company.value = "";
  companyNo.value = "";
  Assignee.value = "";
  assigneeId.value = "";
};
const getPurestatReportData = async (a, b, c) => {
  dialogVisible.value = true;
  titleText.value = b;
  const params = {
    "dto.fileName": a,
    "dto.reporti18n": "zh_CN",
    "dto.confirm": c
  };
  const data = await getPurestatReport(params);
  let data_set = data.toString();
  // 找到 id 为 reportMain 的标签并给第一个 div 添加样式
  const parser = new DOMParser();
  const doc = parser.parseFromString(data_set, "text/html");
  const reportMain = doc.getElementById("reportMain");
  if (reportMain) {
    const firstDiv = reportMain.querySelector("div");
    if (firstDiv) {
      firstDiv.style.display = "none"; // 替换为你想要的样式
    }
  }
  data_set = doc.body.innerHTML; // 更新 data_set
  if (data_set.indexOf("/itsm-webapp") > -1) {
    data_set = data_set.replaceAll("/itsm-webapp", "/api");
  }
  if (data_set.indexOf("../") > -1) {
    data_set = data_set.replaceAll("../", "/api/");
  }
  if (data_set.indexOf("reports!") > -1) {
    data_set = data_set.replaceAll("reports!", "api/reports!");
  }
  ReportData.value = data_set;
};
const selectEngineer = () => {
  dialogRuleRequestNoTableVisible.value = true;
};
const sendRuleRequestNoData = (data: any) => {
  dialogRuleRequestNoTableVisible.value = false;
  engineer.value = data.fullName;
  userId.value = data.userId;
};
const selectCompany = () => {
  dialogRuleCompanyNoTableVisible.value = true;
};
const sendRuleCompanyNoData = (data: any) => {
  dialogRuleCompanyNoTableVisible.value = false;
  company.value = data.orgName;
  companyNo.value = data.orgNo;
};
const selectAssignee = () => {
  dialogAssignee.value = true;
};
const sendAssigneeId = data => {
  dialogAssignee.value = false;
  Assignee.value = data.fullName;
  assigneeId.value = data.userId;
};
//配置项
const getCimReportView = async (a, b, c) => {
  let params;
  titleText.value = b;
  dialogVisible.value = true;
  params = {
    "dto.fileName": a,
    "dto.reporti18n": "zh_CN",
    "dto.confirm": c
  };
  const data = await getConfigReport(params);
  let data_set = data.toString();
  const parser = new DOMParser();
  const doc = parser.parseFromString(data_set, "text/html");
  const reportMain = doc.getElementById("reportMain");
  if (reportMain) {
    const firstDiv = reportMain.querySelector("div");
    if (firstDiv) {
      firstDiv.style.display = "none"; // 替换为你想要的样式
    }
  }
  data_set = doc.body.innerHTML; // 更新 data_set
  if (data_set.indexOf("/itsm-webapp") > -1) {
    data_set = data_set.replaceAll("/itsm-webapp", "/api");
  }
  if (data_set.indexOf("../") > -1) {
    data_set = data_set.replaceAll("../", "/api/");
  }
  if (data_set.indexOf("reports!") > -1) {
    data_set = data_set.replaceAll("reports!", "api/reports!");
  }
  ReportData.value = data_set;
};
//回访记录管理
const proTable = ref<ProTableInstance>();
const dataCallback = (data: any) => {
  return {
    list: data.data,
    total: data.totalSize,
    pageNum: data.page,
    pageSize: data.rows
  };
};
const initParam = ref("");
const columns = reactive<ColumnProps<any>[]>([
  {
    type: "selection"
  },
  {
    prop: "visitId",
    label: "ID",
    sortable: true
  },
  {
    prop: "satisfaction",
    label: "满意度",
    sortable: true,
    render: (h: any) => {
      switch (h.row.satisfaction) {
        case "5":
          return "非常满意";
        case "4":
          return "满意";
        case "3":
          return "一般";
        case "2":
          return "不满意";
        case "1":
          return "非常不满意";
        default:
          return "";
      }
    }
  },
  {
    prop: "state",
    label: "回访状态",
    sortable: true,
    render: (h: any) => {
      switch (h.row.state) {
        case "0":
          return "待回访";
        case "1":
          return "已回访";
        default:
          return "";
      }
    }
  },
  {
    prop: "returnVisitSubmitTime",
    label: "回访发出时间",
    sortable: true
  },
  {
    prop: "returnVisitTime",
    label: "回访回复时间",
    sortable: true
  },
  {
    prop: "returnVisitUser",
    label: "回访对象",
    sortable: true
  },
  {
    prop: "lastUpdater",
    label: "操作者",
    sortable: true
  }
  // { prop: "operation", label: "操作", fixed: "right" }
]);
</script>
<style scoped lang="scss">
.title {
  margin: 10px 0;
}
.el-row {
  background: #ffffff;
  border-bottom: 1px solid #ebeef5;
}
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
}
.grid-content {
  min-height: 30px;
  font-size: 14px;
  line-height: 30px;
  border-radius: 4px;
}
</style>
